//
//  LBXProgressView.m
//  LBXKit
//
//  Created by lbx on 2017/11/8.
//  Copyright © 2017年 lbx. All rights reserved.
//

#import "LBXProgressView.h"

@interface LBXProgressView()
@property (nonatomic, strong) UIView *inProgressView;
@end


@implementation LBXProgressView

- (instancetype)init
{
    if (self = [super init]) {
        
        [self initProgressView];
    }
    
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    [self initProgressView];
}

- (void)initProgressView
{
    _progress = 0.0;
    
    self.inProgressView = [[UIView alloc]init];
    [self addSubview:_inProgressView];
//    _inProgressView.image = [UIImage imageNamed:@"progress_track_forgroundimage"];
    _inProgressView.backgroundColor = [UIColor blueColor];

    CGRect frame = self.frame;
    
    frame.origin = CGPointZero;
    frame.size.width = frame.size.width * (_progress >= 1 ? 1:_progress );
    _inProgressView.frame = frame;
}

- (void)setProgress:(CGFloat)progress
{
    _progress = progress;
    CGRect frame = self.frame;
    //
    frame.origin = CGPointZero;
    frame.size.width = frame.size.width * (_progress >= 1 ? 1:_progress );
    
    self.inProgressView.frame = frame;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGRect frame = self.frame;
    
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = frame.size.height / 2;
    
    
    _inProgressView.layer.masksToBounds = YES;
    _inProgressView.layer.cornerRadius = frame.size.height / 2;

    
    frame.origin = CGPointZero;
    frame.size.width = frame.size.width * (_progress >= 1 ? 1:_progress );
    _inProgressView.frame = frame;
}

@end
